<form action="${ctx}/platrole/form" method="post" id="addPlatRole" enctype="multipart/form-data">
		<input type="hidden" name="roleId" value="${platRole.roleId!}" />
		<div class="form-group form-inline row">
			<div class="col-sm-6">
				<label><span style="color: red" id="roleName">*</span>角色编码：</label>
				<#if platRole?? && platRole.roleCode??>
					<input class="form-control" type="text" name="roleCode" value="${platRole.roleCode!}"  readonly />
				<#else>
					<input class="form-control" type="text" name="roleCode" value=""  required />
				</#if>
			</div>
			<div class="col-sm-6">
				<label><span style="color: red" id="roleName">*</span>角色名：</label>
				<input class="form-control" type="text" name="roleName" value="${platRole.roleName!}"  required />
			</div>
		</div>
</form>
<script>
	$("#addPlatRole").validate({
        rules: {
        	roleCode: {
            	trimRequired : true,
            	unContainSpace : true,
            	validateRoleCode : true
            },
            roleName : {
            	trimRequired : true,
            	unContainSpace : true,
            	validateRoleName : true
            }
        },
        messages: {
        }
	});
	
	$.validator.addMethod("trimRequired", function(value, element) {
		if (value == '') {
			return false;
		}
		if ($.trim(value) == '') {
			return false;
		}
		return true;
	}, "该字段不能为空");
	$.validator.addMethod("unContainSpace", function(value, element) {
		if (value == '' || $.trim(value) == '') {
			return true;
		}
		if ($.trim(value).search(/\s/) != -1) {
			return false;
		}
		return true;
	}, "该字段不能包含空格");
	
	// 返回true验证通过， 返回false验证不通过 
	$.validator.addMethod("validateRoleCode", function(value, element) {
		var roleId = $(":input[name='roleId']").val();
		
		var verificationPassed = false;
		$.ajax({
			url : "${ctx}/platrole/validateRoleCode",
			type : 'post',
			dataType : 'json',
			async : false,
			data : {"roleId" : roleId, "roleCode" : value},
			success : function(data) {
				if (data.result == 'success') {
					verificationPassed = true;
				}
			}
		});
		
		return verificationPassed;
	}, "该字段不能为重复");
	
	// 返回true验证通过， 返回false验证不通过 
	$.validator.addMethod("validateRoleName", function(value, element) {
		var roleId = $(":input[name='roleId']").val();
		
		var verificationPassed = false;
		$.ajax({
			url : "${ctx}/platrole/validateRoleName",
			type : 'post',
			dataType : 'json',
			async : false,
			data : {"roleId" : roleId, "roleName" : value},
			success : function(data) {
				if (data.result == 'success') {
					verificationPassed = true;
				}
			}
		});
		
		return verificationPassed;
	}, "该字段不能为重复");
</script>
<style>
	label{
		margin-right: -30px;
		margin-left: 40px;
	}
	#roleName{
		text-align: center;
		display: inline-block;
		width: 30px;
		height: 30px;
		position: absolute;
		top: 9px;
		left: -6px;
		margin-left: 36px;
	}
	h4{
		font-weight: 700;
		font-size: 20px;
	}
</style>
